package com.lingjtx.im.core.distribute;

import com.lingjtx.im.core.handle.ImMessageHandle;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MessageTypeContextWrapper {

    private final MessageTypeContext context;

    private final ImMessageHandle privateMessage;
    private final ImMessageHandle groupMessage;
    private final ImMessageHandle kefuMessage;
    private final ImMessageHandle systemNoticeMessage;

    public MessageTypeContextWrapper(MessageTypeContext context,
                                     @Qualifier("privateMessage") ImMessageHandle privateMessage,
                                     @Qualifier("groupMessage") ImMessageHandle groupMessage,
                                     @Qualifier("kefuMessage") ImMessageHandle kefuMessage,
                                     @Qualifier("systemNoticeMessage") ImMessageHandle systemNoticeMessage) {
        this.context = context;
        this.privateMessage = privateMessage;
        this.groupMessage = groupMessage;
        this.kefuMessage = kefuMessage;
        this.systemNoticeMessage = systemNoticeMessage;
    }

    // 初始化一次
    @PostConstruct
    public void init() {
        context.setHandlers(privateMessage);
        context.setHandlers(groupMessage);
        context.setHandlers(kefuMessage);
        context.setHandlers(systemNoticeMessage);
    }

    public ImMessageHandle getHandle(byte type) {
        return context.getHandle(type);
    }
}
